Connecting to the postgres sql database
library(odbc)
library(DBI)
library(RPostgreSQL)
password = "Kingjames1611"
DBI::dbDriver('PostgreSQL')
<PostgreSQLDriver>
drv=dbDriver("PostgreSQL")
con=dbConnect(drv,dbname="practical_sql",
host="localhost",
port=5432,
user="postgres",
password=password)
dbListTables(conn = con)
[1] "spatial_ref_sys" "poll_watch"
using the database
library(odbc)
library(DBI)
library(RPostgreSQL)
## Actual code for automating the database
query = "(
select
question_id,
poll_id,
cycle,
state,
pollster_id::float::numeric,
pollster,
sponsors,
display_name,
pollster_rating_id,
pollster_rating_name,
fte_grade,
sample_size::float8::numeric::double precision--when applicable,
population,
population_full,methodology,
office_type,
start_date::date,
end_date::date,
election_date::date,
internal,
partisan,
tracking,
nationwide_batch,
ranked_choice_reallocated,
created_at::timestamptz::timestamp::timestamptz,
notes,
url as source,
race_id,
answer,
candidate_party,
pct::float8::numeric::double precision--when applicable
from poll_watch
where candidate_party = 'REP'
or candidate_party = 'DEM'
and created_at > '2020-09-15'
order by end_date desc,
start_date,
methodology
)"
#processing the query
result_db<- RPostgreSQL::dbGetQuery(conn = con,statement = query)
result_db
Keep in mind that you can also plot the information contained in the database right here in R.
summary(result_db)
question_id poll_id
Min. : 92078 Min. :57025
1st Qu.:112656 1st Qu.:62539
Median :122108 Median :65817
Mean :118354 Mean :65005
3rd Qu.:128123 3rd Qu.:68436
Max. :130600 Max. :70106
cycle state
Length:4229 Length:4229
Class :character Class :character
Mode :character Mode :character
pollster_id pollster
Min. : 11 Length:4229
1st Qu.: 568 Class :character
Median :1189 Mode :character
Mean :1004
3rd Qu.:1416
Max. :1624
sponsors display_name
Length:4229 Length:4229
Class :character Class :character
Mode :character Mode :character
pollster_rating_id pollster_rating_name
Min. : 3.0 Length:4229
1st Qu.:144.0 Class :character
Median :245.0 Mode :character
Mean :271.1
3rd Qu.:383.0
Max. :619.0
NA's :1
fte_grade population
Length:4229 Min. : 140
Class :character 1st Qu.: 760
Mode :character Median : 1000
Mean : 2238
3rd Qu.: 1441
Max. :145588
population_full methodology
Length:4229 Length:4229
Class :character Class :character
Mode :character Mode :character
office_type start_date
Length:4229 Min. :2018-11-12
Class :character 1st Qu.:2019-10-19
Mode :character Median :2020-04-12
Mean :2020-03-06
3rd Qu.:2020-08-16
Max. :2020-09-29
end_date election_date
Min. :2018-11-13 Min. :2020-11-03
1st Qu.:2019-10-26 1st Qu.:2020-11-03
Median :2020-04-15 Median :2020-11-03
Mean :2020-03-11 Mean :2020-11-03
3rd Qu.:2020-08-25 3rd Qu.:2020-11-03
Max. :2020-09-30 Max. :2020-11-03
internal partisan
Mode :logical Length:4229
FALSE:4219 Class :character
TRUE :10 Mode :character
tracking nationwide_batch
Mode:logical Mode :logical
TRUE:663 FALSE:4229
NA's:3566
ranked_choice_reallocated
Mode :logical
FALSE:4229
created_at notes
Min. :2018-12-06 14:40:00 Length:4229
1st Qu.:2019-11-04 08:40:00 Class :character
Median :2020-04-25 01:02:00 Mode :character
Mean :2020-03-22 08:35:41
3rd Qu.:2020-09-02 20:32:00
Max. :2020-10-01 13:02:00
source race_id
Length:4229 Min. :6210
Class :character 1st Qu.:6210
Mode :character Median :6215
Mean :6250
3rd Qu.:6241
Max. :8718
answer candidate_party
Length:4229 Length:4229
Class :character Class :character
Mode :character Mode :character
pct
Min. :21.00
1st Qu.:41.00
Median :44.00
Mean :43.73
3rd Qu.:47.00
Max. :67.00
library(ggplot2)
library(esquisse)
library(gganimate)
#esquisser(result_db
library(dplyr)
library(ggplot2)
p<-result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = "", y = pct, fill = candidate_party) +
geom_boxplot() +
scale_fill_hue() +
theme_classic()+labs(x = "candidate's party", y = "percentage", title = "Boxplot track of 2020 presidential election", caption = "Prepared by Joel Rodriguez")+ theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))
p+transition_time(start_date) +
ease_aes() #+
#transition_time(candidate_party) +
# ease_aes('linear')
library(esquisse)
library(gganimate)
library(dplyr)
library(ggplot2)
p<-result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = "", y = pct, fill = candidate_party) +
geom_boxplot() +
scale_fill_hue() +
theme_classic()+labs(x = "candidate's party", y = "percentage", title = "Boxplot track of 2020 presidential election", caption = "Prepared by Joel Rodriguez")
p+ theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))
NA
NA
library(dplyr)
library(ggplot2)
library(plotly)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: 㤼㸱plotly㤼㸲
The following object is masked from 㤼㸱package:ggplot2㤼㸲:
last_plot
The following object is masked from 㤼㸱package:stats㤼㸲:
filter
The following object is masked from 㤼㸱package:graphics㤼㸲:
layout
mult<- result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = answer, y = pct, fill = candidate_party) +
geom_boxplot() +
scale_fill_hue() +
theme_minimal() +
facet_wrap(vars(state))+ theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))
ggplotly(mult)
`group_by_()` is deprecated as of dplyr 0.7.0.
Please use `group_by()` instead.
See vignette('programming') for more help
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated.
library(ggplot2)
library(esquisse)
library(plotly)
AA<- result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct, fill = candidate_party) +
geom_density(adjust = 1L) +
scale_fill_hue() +
labs(x = "Percentage", y = "Density", title = "Density Plot presidential election 2020",caption = "Prepared by Joel Rodriguez") +
theme_minimal()
ggplotly(AA)
library(gganimate)
result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = "", y = pct, fill = candidate_party) +
geom_violin(adjust = 1L, scale = "area") +
scale_fill_hue() +
labs(x = "Percentage", y = "Density", title = "Density Plot presidential election 2020",caption = "Prepared by Joel Rodriguez") +
theme_minimal()+ theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))+transition_time(start_date) +
ease_aes()+transition_time(start_date) +
ease_aes()
library(gganimate)
library(plotly)
A<- result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = "", y = pct, fill = candidate_party) +
geom_violin(adjust = 1L, scale = "area") +
scale_fill_hue() +
labs(x = "Percentage", y = "Density", title = "Density Plot presidential election 2020",caption = "Prepared by Joel Rodriguez") +
theme_minimal()
ggplotly(A)
NA
result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct, fill = candidate_party) +
geom_histogram(bins = 28L) +
scale_fill_brewer(palette = "Set1") +
labs(x = "Percentage", y = "Density", title = "Density Plot presidential election 2020",caption = "Prepared by Joel Rodriguez") +
theme_minimal() +
theme(legend.position = "none")+transition_time(start_date) +
ease_aes()
g4<- result_db %>%
filter(created_at >=
"2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct,
fill = candidate_party,fill= candidate_party) +
geom_histogram(bins = 28L) +
scale_fill_brewer(palette = "Set1") +
labs(x = "Percentage",
y = "Density",
title = "Density Plot presidential election 2020",caption = "Prepared by Joel Rodriguez") +
theme_minimal() +
theme(legend.position = "none")+ theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))
Duplicated aesthetics after name standardisation: fill
ggplotly(g4)
library(dplyr)
library(ggplot2)
library(plotly)
pk<- result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct, fill = answer) +
geom_density(adjust = 0.2) +
scale_fill_hue() +
theme_minimal()+ theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))+ labs(x = "percentage", title = "Plots divided by candidate",caption = "Prepared by Joel Rodriguez")
ggplotly(pk)
library(dplyr)
library(ggplot2)
result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct, fill = answer) +
geom_density(adjust = 0.2) +
scale_fill_hue() + labs(x = "percentage", title = "Plots divided by candidate",caption = "Prepared by Joel Rodriguez")
theme_minimal()
List of 93
$ line :List of 6
..$ colour : chr "black"
..$ size : num 0.5
..$ linetype : num 1
..$ lineend : chr "butt"
..$ arrow : logi FALSE
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_line" "element"
$ rect :List of 5
..$ fill : chr "white"
..$ colour : chr "black"
..$ size : num 0.5
..$ linetype : num 1
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_rect" "element"
$ text :List of 11
..$ family : chr ""
..$ face : chr "plain"
..$ colour : chr "black"
..$ size : num 11
..$ hjust : num 0.5
..$ vjust : num 0.5
..$ angle : num 0
..$ lineheight : num 0.9
..$ margin : 'margin' num [1:4] 0points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : logi FALSE
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ title : NULL
$ aspect.ratio : NULL
$ axis.title : NULL
$ axis.title.x :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 2.75points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.title.x.top :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 0
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 2.75points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.title.x.bottom : NULL
$ axis.title.y :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 1
..$ angle : num 90
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 2.75points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.title.y.left : NULL
$ axis.title.y.right :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 0
..$ angle : num -90
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 0points 2.75points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.text :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : chr "grey30"
..$ size : 'rel' num 0.8
..$ hjust : NULL
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.text.x :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 2.2points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.text.x.top :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 0
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 2.2points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.text.x.bottom : NULL
$ axis.text.y :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : num 1
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 2.2points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.text.y.left : NULL
$ axis.text.y.right :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : num 0
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 0points 2.2points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.ticks : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ axis.ticks.x : NULL
$ axis.ticks.x.top : NULL
$ axis.ticks.x.bottom : NULL
$ axis.ticks.y : NULL
$ axis.ticks.y.left : NULL
$ axis.ticks.y.right : NULL
$ axis.ticks.length : 'simpleUnit' num 2.75points
..- attr(*, "unit")= int 8
$ axis.ticks.length.x : NULL
$ axis.ticks.length.x.top : NULL
$ axis.ticks.length.x.bottom: NULL
$ axis.ticks.length.y : NULL
$ axis.ticks.length.y.left : NULL
$ axis.ticks.length.y.right : NULL
$ axis.line : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ axis.line.x : NULL
$ axis.line.x.top : NULL
$ axis.line.x.bottom : NULL
$ axis.line.y : NULL
$ axis.line.y.left : NULL
$ axis.line.y.right : NULL
$ legend.background : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ legend.margin : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
..- attr(*, "unit")= int 8
$ legend.spacing : 'simpleUnit' num 11points
..- attr(*, "unit")= int 8
$ legend.spacing.x : NULL
$ legend.spacing.y : NULL
$ legend.key : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ legend.key.size : 'simpleUnit' num 1.2lines
..- attr(*, "unit")= int 3
$ legend.key.height : NULL
$ legend.key.width : NULL
$ legend.text :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 0.8
..$ hjust : NULL
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ legend.text.align : NULL
$ legend.title :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : num 0
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ legend.title.align : NULL
$ legend.position : chr "right"
$ legend.direction : NULL
$ legend.justification : chr "center"
$ legend.box : NULL
$ legend.box.just : NULL
$ legend.box.margin : 'margin' num [1:4] 0cm 0cm 0cm 0cm
..- attr(*, "unit")= int 1
$ legend.box.background : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ legend.box.spacing : 'simpleUnit' num 11points
..- attr(*, "unit")= int 8
$ panel.background : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ panel.border : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ panel.spacing : 'simpleUnit' num 5.5points
..- attr(*, "unit")= int 8
$ panel.spacing.x : NULL
$ panel.spacing.y : NULL
$ panel.grid :List of 6
..$ colour : chr "grey92"
..$ size : NULL
..$ linetype : NULL
..$ lineend : NULL
..$ arrow : logi FALSE
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_line" "element"
$ panel.grid.major : NULL
$ panel.grid.minor :List of 6
..$ colour : NULL
..$ size : 'rel' num 0.5
..$ linetype : NULL
..$ lineend : NULL
..$ arrow : logi FALSE
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_line" "element"
$ panel.grid.major.x : NULL
$ panel.grid.major.y : NULL
$ panel.grid.minor.x : NULL
$ panel.grid.minor.y : NULL
$ panel.ontop : logi FALSE
$ plot.background : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ plot.title :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 1.2
..$ hjust : num 0
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 5.5points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.title.position : chr "panel"
$ plot.subtitle :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : num 0
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 5.5points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.caption :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 0.8
..$ hjust : num 1
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 5.5points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.caption.position : chr "panel"
$ plot.tag :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 1.2
..$ hjust : num 0.5
..$ vjust : num 0.5
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.tag.position : chr "topleft"
$ plot.margin : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
..- attr(*, "unit")= int 8
$ strip.background : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ strip.background.x : NULL
$ strip.background.y : NULL
$ strip.placement : chr "inside"
$ strip.text :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : chr "grey10"
..$ size : 'rel' num 0.8
..$ hjust : NULL
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 4.4points 4.4points 4.4points 4.4points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ strip.text.x : NULL
$ strip.text.y :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : NULL
..$ angle : num -90
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ strip.switch.pad.grid : 'simpleUnit' num 2.75points
..- attr(*, "unit")= int 8
$ strip.switch.pad.wrap : 'simpleUnit' num 2.75points
..- attr(*, "unit")= int 8
$ strip.text.y.left :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : NULL
..$ angle : num 90
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
- attr(*, "class")= chr [1:2] "theme" "gg"
- attr(*, "complete")= logi TRUE
- attr(*, "validate")= logi TRUE
pk<- result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct, fill = answer) +
geom_density(adjust = 6L) +
scale_fill_hue() +
theme_minimal() +
facet_wrap(vars(population_full))+ labs(x = "percentage", title = "Plots divided by methodology",caption = "Prepared by Joel Rodriguez")+ theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))
ggplotly(pk)
Groups with fewer than two data points have been dropped.Groups with fewer than two data points have been dropped.
library(forecast)
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
library(dplyr)
#library(highcharter)
library(tidyselect)
library(esquisse)
a = result_db$pct
a%>%forecast%>%plot()
NA
NA
library(dplyr)
library(ggplot2)
library(dplyr)
library(ggplot2)
result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct, fill = candidate_party) +
geom_density(adjust = 1L) +
scale_fill_viridis_d(option = "plasma") +
theme_minimal()+ labs(x = "percentage", title = "Plots divided by methodology",caption = "Prepared by Joel Rodriguez")+transition_time(start_date) +
ease_aes())
Error: unexpected ')' in:
" theme_minimal()+ labs(x = "percentage", title = "Plots divided by methodology",caption = "Prepared by Joel Rodriguez")+transition_time(start_date) +
ease_aes())"
library(dplyr)
library(ggplot2)
library(dplyr)
library(ggplot2)
library(plotly)
g3<- result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct, fill = candidate_party) +
geom_density(adjust = 1L) +
scale_fill_viridis_d(option = "plasma") +
theme_minimal()+ labs(x = "percentage", title = "Plots divided by methodology",caption = "Prepared by Joel Rodriguez") + theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))
ggplotly(g3)
NA
NA
library(dplyr)
library(ggplot2)
result_db %>%
filter(created_at >=
"2020-09-18 09:12:00" &
created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct, fill = candidate_party) +
geom_histogram(bins = 30L) +
scale_fill_viridis_d(option = "cividis") +
labs(x = "percentage", title = "Plots divided by methodology") +
theme_minimal() +
facet_wrap(vars(notes))+ theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))
library(dplyr)
library(ggplot2)
result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct, fill = candidate_party) +
geom_density(adjust = 1L) +
scale_fill_viridis_d(option = "cividis") +
labs(x = "percentage", title = "Plots divided by methodology") +
theme_minimal() +
facet_wrap(vars(notes))+ theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))
library(dplyr)
library(ggplot2)
library(plotly)
g1<- result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct, fill = candidate_party) +
geom_density(adjust = 1L) +
scale_fill_viridis_d(option = "cividis") +
labs(x = "percentage", title = "Plots divided by methodology") +
theme_minimal() +
facet_wrap(vars(tracking)) + theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))
ggplotly(g1)
library(dplyr)
library(ggplot2)
library(dplyr)
library(ggplot2)
result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = pct, fill = display_name, colour = partisan) +
geom_histogram(bins = 29L) +
scale_fill_viridis_d(option = "viridis") +
scale_color_viridis_d(option = "viridis") +
theme_minimal()
result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = answer, y = pct, colour = candidate_party) +
geom_boxplot(fill = "#238b45") +
scale_color_viridis_d(option = "cividis") +
labs(x = "Candidates",y='percentage', title = "Plots divided by methodology",caption = "Prepared by Joel Rodriguez") +
theme_bw() +
facet_wrap(vars(candidate_party), scales = "free_x")+transition_time(start_date) +
ease_aes() + theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)
library(plotly)
gg<- result_db %>%
filter(created_at >= "2020-09-18 09:12:00" & created_at <= "2020-10-01 17:02:00") %>%
ggplot() +
aes(x = answer, y = pct, colour = candidate_party) +
geom_boxplot(fill = "#238b45") +
scale_color_viridis_d(option = "cividis") +
labs(y= "percentage",x= 'candidates' , "Plots divided by methodology",caption = "Prepared by Joel Rodriguez") +
theme_bw() +
facet_wrap(vars(candidate_party), scales = "free_x") +
theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
)+theme(plot.background = element_rect(fill = "lightblue"))
ggplotly(gg)
library(odbc)
library(DBI)
library(RPostgreSQL)
#dbDisconnect(con)